package com.cyj.dream.admin.service.system.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyj.dream.admin.model.request.SysRoleQueryRequest;
import com.cyj.dream.admin.model.system.SysRole;
import com.cyj.dream.admin.persistence.manager.systems.SysRoleManager;
import com.cyj.dream.admin.service.system.SysRoleService;
import com.cyj.dream.core.constant.pagemodel.PageParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 系统角色业务层实现类
 * @BelongsProject: dream-DreamChardonnay
 * @BelongsPackage: com.dream.DreamChardonnay.service.impl
 * @Author: ChenYongJia
 * @CreateTime: 2021-04-02 09:24
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@Slf4j
@Service
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    private SysRoleManager sysRoleManager;

    /**
     * 分页查询系统角色信息
     *
     * @param pageParam 分页参数
     * @return com.baomidou.mybatisplus.core.metadata.IPage<com.dream.DreamChardonnay.model.system.SysRole>
     * @date 2021/4/21 10:03
     * @author ChenYongJia
     * @version 1.0
     */
    @Override
    public IPage<SysRole> list(PageParam<SysRoleQueryRequest> pageParam) {
        Page<SysRole> page = new Page<>(pageParam.getPageNum(), pageParam.getPageSize());
        IPage<SysRole> dbPage = sysRoleManager.list(page, pageParam.getParam());
        return dbPage;
    }

    /**
     * 根据角色id或者角色权限名称查询角色
     *
     * @param sysRole 角色对象
     * @return com.dream.DreamChardonnay.model.system.SysRole
     * @date 2021/5/6 9:36
     * @author ChenYongJia
     * @version 1.0
     */
    @Override
    public SysRole selectBySysRoleIdOrSysRoleTrueName(SysRole sysRole) {
        return sysRoleManager.selectBySysRoleIdOrSysRoleTrueName(sysRole);
    }

    /**
     * 根据用户id查询用户角色信息集合
     *
     * @param sysUserId
     * @return java.util.List<com.dream.DreamChardonnay.model.system.SysRole>
     * @date 2021/4/2 9:50
     * @author ChenYongJia
     * @version 1.0
     */
    @Override
    public List<SysRole> getUserRoleByUserId(Integer sysUserId) {
        return null;
    }

    /**
     * 添加角色信息
     *
     * @param sysRole 角色对象
     * @return boolean
     * @date 2021/4/21 9:26
     * @author ChenYongJia
     * @version 1.0
     */
    @Override
    public boolean addRoleInfo(SysRole sysRole) {
        log.info("添加角色信息， sysRole 为=======>{}", JSONObject.toJSONString(sysRole));
        return sysRoleManager.addRoleInfo(sysRole);
    }

    /**
     * 修改角色信息
     *
     * @param sysRole 角色对象
     * @return boolean
     * @date 2021/4/21 9:26
     * @author ChenYongJia
     * @version 1.0
     */
    @Override
    public boolean updRoleInfo(SysRole sysRole) {
        log.info("修改角色信息， sysRole 为=======>{}", JSONObject.toJSONString(sysRole));
        return sysRoleManager.updRoleInfo(sysRole);
    }

    /**
     * 逻辑删除角色信息
     *
     * @param sysRole 角色对象集合
     * @return boolean
     * @date 2021/4/21 9:26
     * @author ChenYongJia
     * @version 1.0
     */
    @Override
    public boolean delRoleInfo(List<SysRole> sysRole) {
        log.info("删除角色信息， sysRole 为=======>{}", JSONObject.toJSONString(sysRole));
        return sysRoleManager.delRoleInfo(sysRole);
    }

}
